<script setup lang="ts">
/**
 * @description: 列表
 * @params
 * @author: lxx
 * @date: 2025-07-03 15:16:08"
 * @version: V1.0.0
 */
import { dataPageApi, dataBatchDelApi } from '@/api/system/dictItem'
import type { ItemFormInt } from '@/api/system/dictItem/types'
import AddEditForm from './AddEditForm.vue'
import { usePage } from '@/hooks/system/useFramework'
const route = useRoute()

console.log(route.query)

// 查询参数
const queryParams = ref({
  keywords: '',
  dictCode: route.query.dictCode
})
// 查询的FormRef
const queryFormRef = ref()

// 新增编辑FormRef
const addEditFormRef = ref()

const { queryPage, tableData, loading, handleQuery, handleResetQuery, handleAddEdit, handleDelete, handleSelectChange } = usePage<ItemFormInt>(
  dataPageApi,
  dataBatchDelApi,
  queryParams,
  queryFormRef,
  addEditFormRef
)
</script>
<template>
  <div class="web-container-box flex-start-start column">
    <!-- 搜索区域 -->
    <div class="search-container">
      <el-card shadow="hover">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true">
          <el-form-item label="关键字" prop="keywords">
            <el-input v-model="queryParams.keywords" placeholder="字典项名称/值" clearable @keyup.enter="handleQuery" />
          </el-form-item>

          <el-form-item class="search-buttons">
            <el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
            <el-button icon="refresh" @click="handleResetQuery">重置</el-button>
            <el-button type="success" icon="plus" @click="handleAddEdit('add')">新增</el-button>
            <el-button type="danger" icon="delete" @click="handleDelete()">删除</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
    <!-- 列表 -->
    <el-card shadow="hover" class="data-table">
      <el-table fit v-loading="loading" width="100%" highlight-current-row :data="tableData" border @selection-change="handleSelectChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="字典项名称" prop="dictLabel" />
        <el-table-column label="字典项值" prop="dictValue" />
        <el-table-column label="排序" prop="sort" />
        <el-table-column label="状态" prop="status">
          <template #default="scope">
            <el-tag :type="scope.row.status === 1 ? 'success' : 'info'">
              {{ scope.row.status === 1 ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="220">
          <template #default="scope">
            <el-button type="primary" link size="small" icon="edit" @click.stop="handleAddEdit('edit', scope.row)">编辑</el-button>
            <el-button type="danger" link size="small" icon="delete" @click.stop="handleDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-if="queryPage.total > 0"
        layout="prev, pager, next, sizes, total"
        :total="queryPage.total"
        v-model:current-page="queryPage.pageNum"
        v-model:page-size="queryPage.pageSize"
        @current-change="handleQuery"
        @size-change="handleQuery"
      />
    </el-card>
    <!-- 新增、编辑弹窗 -->
    <AddEditForm ref="addEditFormRef" />
  </div>
</template>
<style lang="scss" scoped></style>
